<template>
  <view>
    <view class="input-search">
    	<uni-easyinput prefixIcon="search"  trim="all" v-model="keyword" :styles="styles" :placeholderStyle="placeholderStyle"></uni-easyinput>
    	<button @click="search">搜索</button>
    </view>
    <uni-table ref="table" type="" stripe :loading="loading" border emptyText="暂无更多数据" filter-type="search">
		<uni-tr v-for="(item, index) in card_arr" :key="index" >
			<uni-td width="100%" align="left" class="td-class" >
				<div @click="selectes(item)">
					<view>
						<text>物料：{{ item.name }}</text>
					</view>
					<view>
						<text>编码：{{ item.cInvCode }}</text>
						<text>规格：{{ item.specification }}</text>
					</view>
					<view>
						<text class="font-red">数量：{{ item.iQuantity }}</text>
						<text>单位：{{ item.unit }}</text>
					</view>
					<view>
						<text class="font-red">货架：{{ item.shelves_name }}</text>
						<!-- <text>批号：{{ item.cBatch }}</text> -->
					</view>
					
				</div>
			</uni-td>
        </uni-tr>
    </uni-table>
    <view class="uni-pagination-box">
		<uni-pagination show-icon :page-size="pageSize" :current="currentPage"
        :total="total" @change="change" />
	</view>
  </view>
</template>

<script>
// 引入uni-ui组件
import {
  uniPagination,
  uniIcons,
  uniCard,
  uniTable,
  uniTr,
  uniTh,
  uniTd,
  uniEasyinput
} from "@dcloudio/uni-ui"
import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
export default {
  data() {
    return {
      card_arr: [],//当前页码的表格数据
      pageSize: 15,// 每页数据量
      currentPage: 1,// 当前页
      total: 0,// 数据总量
      loading: false,
      item: '',
      id: '',
	  barcode:'',
	  placeholderStyle:'font-size:16px;',
	  styles:{
	  	borderColor: '#999'
	  },
	  keyword:'',
	  where:' 1=1 '
    }
  },
  components: {
    uniPagination,
    uniIcons, //uni-ui的icons组件
    uniCard, //uni-ui的卡片组件
    uniTable,
    uniTr,
    uniTh,
    uniTd,
	uniEasyinput
  },
  methods: {
    // 点击关闭的事件回调
    close() {
      uni.navigateBack({})
    },
	// 搜索
	search() {
		this.getlist();
	},
    //获取列表
    getlist() {
		uni.showLoading();
		if(this.keyword!=''){
			this.where = " name like '%"+this.keyword+"%' or specification like '%"+this.keyword+"%' or cInvCode like '%"+this.keyword+"%' or shelves_name like '%"+this.keyword+"%'"
		}else{
			this.where = ' 1=1 '
		}
		
		this.$Db.queryCount('kc',this.where).then(res => {
			this.total = res[0].num;//获得总页数
		})
		this.$Db.queryDataList('kc',this.currentPage,this.pageSize,this.where).then(res => {
			this.card_arr = res;
			uni.hideLoading();
		})
    },
    change(e) {
      this.currentPage = e.current
      this.getlist()
    },
	selectes(item) {
	  if (item == '') return
	  if(this.flag == 'check'){
		  //监听盘点
		  uni.navigateBack({
			delta: 1,
			success: () => {
			  uni.$emit("getKc", item)
			}
	  });
	  }
	},
  },
  mounted(e) {
    //his.getlist()
  },
  onLoad(e) {
	this.getlist()
	this.flag = e.flag
	this.$Func.setBarTitle('即时库存')
  }
}
</script>
<style lang="less">
</style>